''' Casual Mature Gamers

    Title: cmg_menus_python
    Version: 2.4 (REWRITE IN PROCESS, STILL 2.3)
    Description: Creates a menu with all CmG commands recoded in Python
'''

# Eventscripts imports
import es
import popuplib

# Version info
__version__ = '2.4b1'
es.ServerVar('cmg_menus_ver', __version__).makepublic()

# Register this addon with EventScripts
info = es.AddonInfo()
info.name     = 'cmg_menus'
info.version  = '__version__'
info.url      = 'http://cmgsourceclan.com/'
info.basename = 'cmg_menus'
info.author   = 'CmG Sketchy and CmG Knight'

# Menu Stuff
def load():
    # Create the public cmg menu, and the say command to access it.
    es.regsaycmd('!cmg', 'cmg_menus/cmgMenu') 

    cmgMenu = popuplib.create('cmgMenu')

	    admin_menu.addoption('4', "Add a Survivor Bot") 
		
	cmgMenu.settitle ('        CmG Menu')
	cmgMenu.settitle('________________')
	cmgMenu.addoption ('->1. GunGame Menu')
	cmgMenu.addoption ('->2. Server Rules')
	cmgMenu.addoption ('->3. Chat Commands')
	cmgMenu.addoption ('->4. FunSounds List')
	cmgMenu.addoption ('->5. PsychoStats')
	cmgMenu.addoption ('->6. ManiStats')
	cmgMenu.addoption ('->7. Join Ventrillo')
	cmgMenu.addoption ('->8. Listen to Radio')
	cmgMenu.addoption ('->9. Switch Servers')
#	cmgMenu.addoption ('->9. CmG Links')
	cmgMenu.addline ('------------------------')
	cmgMenu.addoption ('->0.         Exit')
	cmgMenu.addline ('Casual Mature Gamers')
	cmgMenu.addline ('@ cmgsourceclan.com')

	es popup select cmgMenu 1 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 2 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 3 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 4 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 5 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 6 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 7 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 8 cmg_menus/cmg_menu_selection
	es popup select cmgMenu 9 cmg_menus/cmg_menu_selection

	cmgMenu.timeout("send",5)
    cmgMenu.timeout("view",30) 
	
    # Create the Admin menu, and the say command to access it.
    es.regsaycmd('!cmg_admin', 'cmg_menus/cmgAdminMenu \"admin\" #admin') 
	
	cmgAdminMenu = popuplib.create('cmgAdminMenu')
	
	cmgAdminMenu.addline ('  CmG Admin Menu')
	cmgAdminMenu.addline ('________________')
	cmgAdminMenu.addline ('->1. Mani Admin')
	cmgAdminMenu.addline ('->2. Global Ban')
	cmgAdminMenu.addline ('->3. Knife Menu')
	cmgAdminMenu.addline ('->4. CmG Menu')
	cmgAdminMenu.addline ('------------------------')
	cmgAdminMenu.addline ('->0.         Exit')
	cmgAdminMenu.addline ('------------------------')
	cmgAdminMenu.addline ('Casual Mature Gamers')
	cmgAdminMenu.addline ('@ cmgsourceclan.com')

	es popup select cmgAdminMenu 1 cmg_menus/cmg_admin_menu_selection
	es popup select cmgAdminMenu 2 cmg_menus/cmg_admin_menu_selection
	es popup select cmgAdminMenu 3 cmg_menus/cmg_admin_menu_selection
	es popup select cmgAdminMenu 4 cmg_menus/cmg_admin_menu_selection

	cmgAdminMenu.timeout("send",5)
    cmgAdminMenu.timeout("view",30) 
	
    # Create the GG menu, and the say command to access it.
    es.regsaycmd('!gg', 'cmg_menus/cmgGGMenu') 

	cmgGGMenu = popuplib.create('cmgGGMenu')
	
	cmgGGMenu.addline ('       CmG GG Menu      ')
	cmgGGMenu.addline ('________________________')
	cmgGGMenu.addline ('->1. Top 10 Winners    ')
	cmgGGMenu.addline ('->2. Current Leader    ')
	cmgGGMenu.addline ('->3. Current Scores    ')
	cmgGGMenu.addline ('->4. Your Current Rank ')
	cmgGGMenu.addline ('->5. Your Current Level')
	cmgGGMenu.addline ('------------------------')
	cmgGGMenu.addline ('->0.  Exit')
	cmgGGMenu.addline ('------------------------')
	cmgGGMenu.addline ('Casual Mature Gamers')
	cmgGGMenu.addline ('@ cmgsourceclan.com')

	es popup select cmgGGMenu 1 cmg_menus/cmg_gg_menu_selection
	es popup select cmgGGMenu 2 cmg_menus/cmg_gg_menu_selection
	es popup select cmgGGMenu 3 cmg_menus/cmg_gg_menu_selection
	es popup select cmgGGMenu 4 cmg_menus/cmg_gg_menu_selection
	es popup select cmgGGMenu 5 cmg_menus/cmg_gg_menu_selection

	cmgGGMenu.timeout("send",5)
    cmgGGMenu.timeout("view",30) 


	es.msg("#multi", "[#greenCmG Menu#default]#defaultversion #lightgreen __version__ #defaultloaded!")

def cmg_admin_menu_selection():
 	if (server_var['_popup_choice'] == '1'):
		es.sexec server_var(_popup_userid) admin
	if (server_var['_popup_choice'] == '2'):
		es.doblock('GlobalBan/banReasonList')
	if (server_var['_popup_choice'] == '3'):
		es_.exec server_var(_popup_userid) say !kr_menu
	if (server_var['_popup_choice'] == '4'):
		es.sexec server_var(_popup_userid) say !cmg
		
def cmg_gg_menu_selection():
 	if (server_var['_popup_choice'] == '1'):
		es.sexec server_var(_popup_userid) say !top10
	if (server_var['_popup_choice'] == '2'):
		es.sexec server_var(_popup_userid) say !leader
	if (server_var['_popup_choice'] == '3'):
		es.sexec server_var(_popup_userid) say !score
	if (server_var['_popup_choice'] == '4'):
		es.sexec server_var(_popup_userid) say !rank
	if (server_var['_popup_choice'] == '5'):
		es.sexec server_var(_popup_userid) say !level

def cmg_menu_selection():
    if (server_var['_popup_choice'] == '1'):
        es.doblock('cmg_menus/cmg_gg_menu')
    if (server_var['_popup_choice'] == '2'):
        es.sexec server_var(_popup_userid) say @ma_browse cmgsourceclan.com/cssdownloads/web_shortcuts/cmg_server_rules.htm
    if (server_var['_popup_choice'] == '3'):
        es.sexec server_var(_popup_userid) say @ma_browse cmgsourceclan.com/cssdownloads/web_shortcuts/cmg_chat_commands.htm
    if (server_var['_popup_choice'] == '4'):
        es.sexec server_var(_popup_userid) say @ma_browse cmgsourceclan.com/cssdownloads/web_shortcuts/cmg_public_sounds.htm
    if (server_var['_popup_choice'] == '5'):
 		# init my vars
 		es.set("cmg_users_steamid", "0")
		es.set("cmg_mani_token1", "0")
		es.set("cmg_mani_token2", "0")
		es.set("cmg_PS_search_string", "0")

		# get users steamid so it can be used in the search criteria to go straight to the players own stats.
		es.server.queuecmd('es_getplayersteamid cmg_users_steamid server_var(_popup_userid)')

		# break the search string up into tokens (minus the steamid) so the steamid is interchangeable
		es.format("cmg_mani_token1", "@ma_browse cmgsourceclan.com/psychostats/server2/index.php?q=")
		es.format("cmg_mani_token2", "&submit=1")

		# create what will be the search string on the psychostats site to go straight to the users stats
		es.format("cmg_PS_search_string", "%1%2%3", server_var['cmg_mani_token1'], server_var['cmg_users_steamid'], server_var['cmg_mani_token2'])
		es.sexec server_var(_popup_userid) say server_var(cmg_PS_search_string)
    if (server_var['_popup_choice'] == '6'):
 		# init my vars
		es.set("cmg_users_steamid", "0")
		es.set("cmg_mani_token1", "0")
		es.set("cmg_mani_token2", "0")
		es.set("cmg_mani_token3", "0")
		es.set("cmg_MS_search_string", "0")

		# get users steamid so it can be used in the search criteria to go straight to the players own stats.
		es.server.queuecmd('es_getplayersteamid cmg_users_steamid server_var(_popup_userid)')

		# break the search string up into tokens (minus the steamid) so the steamid is interchangeable
		es.format("cmg_mani_token1", "@ma_browse cmgsourceclan.com/manistats/server2/index.php?ipath=css.php&ID=")
		es.format("cmg_mani_token2", "&lng=English&min=0&anzeige=10000000000&hdatei=0&search=")
		es.format("cmg_mani_token3", "&orderby=rank&style=MSR_Black&sort=ASC")

		# create what will be the search string on the manistats site to go straight to the users stats
		es.format("cmg_MS_search_string", "%1%2%3%4%5", server_var['cmg_mani_token1'], server_var['cmg_users_steamid'], server_var['cmg_mani_token2'], server_var['cmg_users_steamid'], server_var['cmg_mani_token3'])
		# execute the command and fetch the users stats.
		es.sexec server_var(_popup_userid) say server_var(cmg_MS_search_string)
    if (server_var['_popup_choice'] == '7'):
        es.sexec server_var(_popup_userid) say !vent
    if (server_var['_popup_choice'] == '8'):
        es.sexec server_var(_popup_userid) say @ma_browse cmgsourceclan.com/cssdownloads/streams/radio_off.htm
    if (server_var['_popup_choice'] == '9'):
        es.sexec server_var(_popup_userid) say !switch
#	if (server_var['_popup_choice'] == '9'):
#		es.sexec server_var(_popup_userid) say @ma_browse cmgsourceclan.com/cssdownloads/web_shortcuts/cmg_servers_and_links.html

def cmg_popup_admin():
 	es.set("cmg_user", "0")
	_wrap_es_getcmduserid('cmg_user')
	es.server.queuecmd('es popup isqueued cmgAdminMenu cmg_queued server_var(cmg_user)')
	# If its not already queued, then send the menu to the user.
	if (server_var['cmg_queued'] == "0"):
		es.server.queuecmd('es popup send cmgAdminMenu server_var(cmg_user)')
		
def cmg_gg_menu():
 	es.set("cmg_user", "0")
	_wrap_es_getcmduserid('cmg_user')
	es.server.queuecmd('es popup isqueued cmgGGMenu cmg_queued server_var(cmg_user)')
	# If its not already queued, then send the menu to the user.
	if (server_var['cmg_queued'] == "0"):
		es.server.queuecmd('es popup send cmgGGMenu server_var(cmg_user)')

def cmg_popup():
 	es.set("cmg_user", "0")
	_wrap_es_getcmduserid('cmg_user')
	es.server.queuecmd('es popup isqueued cmgMenu cmg_queued server_var(cmg_user)')
	# If its not already queued, then send the menu to the user.
	if (server_var['cmg_queued'] == "0"):
		es.server.queuecmd('es popup send cmgMenu server_var(cmg_user)')
		
def unload():
    # Destroy popup menus so the console dont bitch when the mods reloaded. Also unregister client commands.
 	popuplib.delete('cmgMenu')
 	popuplib.delete('cmgAdminMenu')
 	popuplib.delete('cmgGGMenu')
	es.unregsaycmd('!cmg')
	es.unregsaycmd('!cmg_admin')
	es.unregsaycmd('!gg')
	es.msg("#multi", "[#greenCmG Menu#default]#defaultversion #lightgreen __version__ #defaultunloaded!")